package com.ywh.composetest.activity

import android.os.Bundle
import android.widget.Button
import androidx.activity.ComponentActivity
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import com.ywh.composetest.R
import com.ywh.composetest.widget.CommonTipDialog

class ComposeViewTestActivity : ComponentActivity() {

    private val showADialogState = mutableStateOf(false)
    private val showBDialogState = mutableStateOf(false)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_compose_view_test)
        val btn = findViewById<Button>(R.id.btn)
        val composeView = findViewById<ComposeView>(R.id.composeView) ?: return


        btn.setOnClickListener {
            showADialogState.value = true
            composeView.removeAllViews()
            showADialog(composeView)
        }
    }

    private fun showADialog(composeView: ComposeView) {
        composeView.setContent {
            CommonTipDialog(
                showDialogState = showADialogState,
                tip = "沙发客撒谎开发货时间啊哈飞机设计啊发哈浆纱机阿发合计沙发手机哈发"
            ) {
                showADialogState.value = false

                showBDialogState.value = true
                composeView.removeAllViews()
                showBDialog(composeView)
            }
        }
    }

    private fun showBDialog(composeView: ComposeView) {
        composeView.setContent {
            CommonTipDialog(
                showDialogState = showBDialogState,
                tip = "业务额腌入味也i日午夜iUR有外iu也iUR有外iu饿呀体悟饿哦图网IE一日无饿哦i人呀我饿u"
            ) {
                showBDialogState.value = false
            }
        }
    }
}